package mailsystem.states;

import mailsystem.Connection;
import mailsystem.TelephoneResources;

public class ConnectedStatus implements State {

	@Override
	public void runAction(Connection c, String key)
	{
		if (key.equals("#")) {
			c.setCurrentMailbox(c.getSystem().findMailbox(c.getAccumulatedKeys()));
			if (c.getCurrentMailbox() != null) {
				c.setState(Connection.RECORDING);				
				c.speakAllPhones(c.getCurrentMailbox().getGreeting());				
			} else
				c.speakAllPhones(TelephoneResources.INCORRECTMAILBOX);				
			c.setAccumulatedKeys("");
		} else
			c.setAccumulatedKeys(c.getAccumulatedKeys() + key);			
	}
}
